#!/usr/bin/python2.7
#coding:UTF-8
 
'''
Created on 28 апр. 2014 г.

@author: nww
'''
import socket
import sys
from numpy import arange, sin, pi
import time

server_address = ('localhost', 10000)

# Create a TCP/IP socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
print >>sys.stderr, 'connecting to %s port %s' % server_address
s.connect(server_address)

t = arange(0.0,3.0,0.01)
i = 0
while True:
    message_l = [chr(int((ti+1)*127)) for ti in sin(2*pi*t+i)]
    message = ''
    for ti in message_l:
        message += ti
#    print message
    i += 0.05
    print >>sys.stderr, '%s:%d sending data' % (s.getsockname())
    s.send(message)
    time.sleep(1)
    # Read responses on both sockets
#   for s in socks:
#       data = s.recv(1024)
#       print >>sys.stderr, '%s: received "%s"' % (s.getsockname(), data)
#       if not data:
#           print >>sys.stderr, 'closing socket', s.getsockname()
#           s.close()